﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace UBlockly.Compotent
{
    internal class UParamComponentAnchor : BlockAnchor,IUAnchor
    {
        protected override void UpdateSubAuchorList()
        {
            base.UpdateSubAuchorList();
            if (transform.childCount == 2)  
            {
                subAnchorList.RemoveAt(0);
            }
        }

        void IUAnchor.Resize()
        {
            UpdateSubAuchorList();
            if (subAnchorList == null || subAnchorList.Count == 0)
                return;
            var b = subAnchorList[0];
            if(!(b as UBlockAnchor))
                throw new System.Exception("UParamComponentAnchor UnKnowerror");
            b.Resize();
            b.SetPosition(new Vector2(BlockGraphicSize.PackerComponentBorder, 0));
            SetSize(new Vector2(b.GetSize().x + BlockGraphicSize.PackerComponentBorder * 2, b.GetSize().y + BlockGraphicSize.PackerComponentBorder * 2));           
        }

        void IUAnchor.SetPosition(Vector2 pos)
        {
            RectTransform.anchoredPosition = pos;
        }
        Vector2 IUAnchor.GetSize()
        {
            return base.GetSize();
        }
        Vector2 IUAnchor.GetPostion()
        {
            return RectTransform.anchoredPosition;
        }
    }
}
